package com.nageoffer.jobtrain.judge.common.result;

import com.nageoffer.jobtrain.judge.common.enums.ExecuteJudeCodeEnums;
import lombok.Data;

import java.util.List;

/**
 * 系统代码沙箱执行结果包装类
 */
@Data
public class SandBoxExecuteResult {
    /**
     * 执行结果
     */
    private ExecuteJudeCodeEnums executeJudeCodeEnums;

    /**
     * 异常信息
     */
    private String errorMessage;

    /**
     * 执行输出结果列表
     */
    private List<String> executeOutPutList;

    /**
     * 占用内存
     */
    private Long useMemory;

    /**
     * 消耗时间
     */
    private Long useTime;

    /**
     * 设置失败状态（带错误消息）
     */
    public static SandBoxExecuteResult fail(ExecuteJudeCodeEnums executeJudeCodeEnums, String errorMessage) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setExecuteJudeCodeEnums(executeJudeCodeEnums);
        result.setErrorMessage(errorMessage);
        return result;
    }

    /**
     * 设置失败状态（使用默认消息）
     */
    public static SandBoxExecuteResult fail(ExecuteJudeCodeEnums executeJudeCodeEnums) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setExecuteJudeCodeEnums(executeJudeCodeEnums);
        result.setErrorMessage(executeJudeCodeEnums.getDescribe());
        return result;
    }

    /**
     * 设置失败状态（带输出、内存、时间）
     */
    public static SandBoxExecuteResult fail(ExecuteJudeCodeEnums executeJudeCodeEnums, List<String> executeOutPutList, Long useMemory, Long useTime) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setExecuteJudeCodeEnums(executeJudeCodeEnums);
        result.setErrorMessage(executeJudeCodeEnums.getDescribe());
        result.setExecuteOutPutList(executeOutPutList);
        result.setUseMemory(useMemory);
        result.setUseTime(useTime);
        return result;
    }

    /**
     * 设置成功状态
     */
    public static SandBoxExecuteResult success(ExecuteJudeCodeEnums executeJudeCodeEnums, List<String> executeOutPutList, Long useMemory, Long useTime) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setExecuteJudeCodeEnums(executeJudeCodeEnums);
        result.setExecuteOutPutList(executeOutPutList);
        result.setUseMemory(useMemory);
        result.setUseTime(useTime);
        return result;
    }
}

